﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Text.RegularExpressions;

namespace BLL.Concrete.forms.users
{
    public class AdministradorData : IDataErrorInfo
    {
        public const string MatchEmailPattern =
            @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
     + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
				[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
     + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
				[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
     + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";
        public String Nombre { get; set; }
        public String Apellido { get; set; }
        public String Email { get; set; }
        public String UserName { get; set; }
        public String Password { get; set; }
        public String RepeatPassword { get; set; }
        public List<String> Roles { get; set; }
        public Guid UserId { get; set; }

        #region IDataErrorInfo Members
        public string Error { get; set; }

        public string this[string columnName]
        {
            get
            {
                if ((columnName == "UserId") && UserId == null)
                {
                    Error = "Nombre de usuario invalido";
                    return "*";
                }
                else if ((columnName == "UserName") && UserName == null)
                {
                    Error = "Nombre de usuario invalido";
                    return "*";
                }
                else if ((columnName == "Email") && Email == null)
                {
                    Error = "Email invalido";
                    return "*";
                }
                else if ((columnName == "Email") && !Regex.IsMatch(Email, MatchEmailPattern))
                {
                    Error = "Email invalido";
                    return "*";
                }
                else if ((columnName == "Apellido") && Apellido == null)
                {
                    Error = "Apellido invalido";
                    return "*";
                }
                else if ((columnName == "Nombre") && Nombre == null)
                {
                    Error = "Nombre invalido";
                    return "*";
                }
                else if ((columnName == "Roles") && Roles.Count != 0)
                {
                    var __p = Roles.Where(u => u != "false").ToList();
                    if (__p.Count == 0)
                    {
                        Error = "Debe seleccionar al menos un (1) rol";
                        return "*";
                    }
                }
                else if ((columnName == "Password") && Password == null)
                {
                    Error = "Contraseña invalida";
                    return "*";
                }
                else if ((columnName == "RepeatPassword") && RepeatPassword == null)
                {
                    Error = "Debe repetir la contraseña";
                    return "*";
                }
                else if ((columnName == "Password" || columnName == "RepeatPassword") && RepeatPassword != null && Password != null && RepeatPassword != Password)
                {
                    Error = "Contraseña invalida";
                    return "*";
                }
                return null;
            }
        }

        #endregion
    }
}
